import request from '../../utils/request'
import { NEWS_SAVE } from '../constants'

export const getNewsAc = (payload) => ({
  type: NEWS_SAVE,
  news: payload,
})

export const getNews = (channelId) => {
  return async (dispatch) => {
    const {
      data: {
        data: { results },
      },
    } = await request.get(
      `/articles?channel_id=${channelId}&timestamp=${Date.now()}`
    )
    dispatch(getNewsAc(results))
  }
}
